package com.zsj.hello.three;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zsj.hello.util.BaseUtil;
import com.zsj.hello.util.RabbimqFactoryUtil;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;

/**
 * @author https://gitee.com/zhengshengjun
 * @date 2023/8/29.
 */
public class Consumer01 {

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbimqFactoryUtil.getRabbitMQChannel();

        DeliverCallback deliverCallback = (t, m) -> {
            System.out.println("消费者1号消费消息为：" + new String(m.getBody()) + "  And tag为：" + t);
            /**
             * m.getEnvelope().getDeliveryTag() todo
             * 这段代码是什么意思呢？
             */
            channel.basicAck(m.getEnvelope().getDeliveryTag(),false);
        };

        CancelCallback cancelCallback = (t) -> {
            System.out.println("取消消费");
        };

        channel.basicConsume("zsj", false, deliverCallback, cancelCallback);
//        channel.basicAck(,false);

    }
}
